<?php if (!defined("_ECRIRE_INC_VERSION")) return;

 if (!function_exists('ppr'))
 {
     function ppr($var)
     {
         echo '<pre>';
         print_r($var);
         echo '</pre>';
    
     }
 }
 
 if (!function_exists('ppre'))
 {
     function ppre($var)
     {
         ppr($var);
         exit;
     }
 }



function formulaires_ecatalogue_article_prices_charger_dist($id_article) {
    $valeurs = array();
	$valeurs['id_article']=_request('id_article');
    return $valeurs;
}


function formulaires_ecatalogue_article_prices_verifier_dist($id_article){
    $erreurs = array();
    return $erreurs;
}


function formulaires_ecatalogue_article_prices_traiter_dist($id_article) {
    $result = array();
    $prices = _request('price');
         
    $id_article = _request('id_article');
    
   
    
    if (is_array($prices))
    {
       foreach($prices as $group=>$price)
       {                                      
          $sql_s = '';
          $sql_s = 'select * from spip_ecatalogue_prices where id_article = '.$id_article.' and id_group = '.$group;
          $res = sql_query($sql_s);
          $record = '';
          $record = sql_fetch_all($res);
          if (is_array($record)&&(!empty($record)))
          {
              $sql_iu = 'Update spip_ecatalogue_prices set price = '.$price.' where id_article = '.$id_article.' and id_group = '.$group;
          }
          else
          {
              $sql_iu = 'Insert into spip_ecatalogue_prices (id_article,id_group,price) value('.$id_article.','.$group.','.$price.')';
          }
          
          sql_query($sql_iu);
          
         
          
       } 
    }
    
    
    
    return $result;
}

?>